/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package objective_functions;

import problems.ZDT6;

/**
 *
 * @author robson
 */
public class ZDT6_F2 implements ObjectiveFunction {
    
    private double gValue;    
    private ZDT6 zdt6;
    private double f1;
    
    public ZDT6_F2( ZDT6 zdt6 ) {
        this.zdt6 = zdt6;
    }    

    public double function( double[] dimension ) {
        
        f1 = ( (ZDT6_F1) zdt6.getFunctions().get(0)).getResult();
        
        return g( dimension ) * ( 1.0 - Math.pow( f1/g( dimension ), 2 ) );
    }
    
    private double g ( double[] dimension ) {
        double sum = 0.0;
        
        for( int i = 1; i < dimension.length; i++ ) {
            sum += dimension[i];
        }
        
        gValue = 1.0 + ( 9.0 * Math.pow( sum / (dimension.length - 1 ), 0.25 ) );
        
        return gValue;
    }

    public double getGValue() {
        return gValue;
    }
}
